import os
import urllib3
import json
import shutil
import notify
import deploy_config

def sync_config_to_preview(url_config, request_configs, context):
    '''同步CF_配置到体验服'''
    cwd = os.getcwd()

    conf = url_config["TEST"]
    tempdir = os.path.join(cwd, "temp/" + conf["local_dir"])
    print("temp dir " + tempdir)
    if os.path.exists(tempdir):
        shutil.rmtree(tempdir)
    os.mkdir(tempdir)

    configs = request_configs(conf, tempdir, "prefix", "CF_")
    deploy_config.deploy(configs, context)